package com.atguigu.tingshu.user.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceHttpClientImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author GQS @Date 2024/11/1/17:09 @Description
 * 使用第三方sdk完成微信登录
 */
@Configuration
public class WxLoginSDKConfig {

  @Autowired
  private WxLoginConfig wxLoginConfig;


  /**
   * bean初始化
   * @return
   */
  @Bean
  public WxMaService wxMaService(){
    //初始化
    WxMaService wxMaService = new WxMaServiceHttpClientImpl();
    //配置初始化
    WxMaDefaultConfigImpl wxMaConfig = new WxMaDefaultConfigImpl();
    wxMaConfig.setSecret(wxLoginConfig.getAppSecret());
    wxMaConfig.setAppid(wxLoginConfig.getAppId());
    //保存配置
    wxMaService.setWxMaConfig(wxMaConfig);
    //返回
    return wxMaService;
  }
}
